package com.example.myui.activity;
/*
* 流式布局
* */

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.example.myui.R;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagAdapter;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.Set;

import butterknife.BindView;
import butterknife.ButterKnife;

public class FlowLayoutActivity extends AppCompatActivity {

    @BindView(R.id.id_flowlayout1)
    TagFlowLayout flowLayout1;
    @BindView(R.id.id_flowlayout2)
    TagFlowLayout flowLayout2;
    private String[] companys = new String[]
            {"全部", "未融资", "天使轮", "A轮", "B轮", "C轮", "D轮以上"};
    private String[] employees = new String[]
            {"全部", "0-20人", "20-299人", "100-499人", "500-999人", "10000-9999人"};
    private String TAG = FlowLayoutActivity.class.getSimpleName();


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_flow);
        ButterKnife.bind(this);


        TagAdapter adapter1 = new TagAdapter(companys) {
            @Override
            public View getView(FlowLayout parent, int position, Object o) {
                TextView tv = (TextView) LayoutInflater.from(FlowLayoutActivity.this).inflate(R.layout.tv, flowLayout1, false);
                tv.setText((String) o);
                return tv;
            }
        };
        flowLayout1.setAdapter(adapter1);

        flowLayout1.setOnSelectListener(new TagFlowLayout.OnSelectListener() {
            @Override
            public void onSelected(Set<Integer> selectPosSet) {
                Log.i(TAG, "onSelected: " + selectPosSet);
            }
        });

        TagAdapter adapter = new TagAdapter(employees) {
            @Override
            public View getView(FlowLayout parent, int position, Object o) {
                TextView tv = (TextView) LayoutInflater.from(FlowLayoutActivity.this).inflate(R.layout.tv, flowLayout2, false);
                tv.setText((String) o);
                return tv;
            }
        };
        adapter.setSelectedList(0);
        flowLayout2.setAdapter(adapter);
    }
}
